package com.man;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.std.DB;
import com.std.OrderItem;

public class OrderItemCtrl {
	private DB db;
	public OrderItemCtrl(){
		db=new DB();
	}
	public void close() {
		db.close();
	}
	public List<OrderItem> getItems(int orderId) {
		String sql="select * from order_item_t,book_t where order_item_t.book_id=book_t.book_id and order_id=?";
		Object []params={orderId};
		db.execute(sql, params);
		List<OrderItem> orderItemList=new ArrayList<OrderItem>();
		ResultSet rs=db.getResultset();
		try {
			while(rs.next()){
				OrderItem orderItem=new OrderItem();
				orderItem.setAmount(rs.getInt("amount"));
				orderItem.setBookId(rs.getInt("book_id"));
				orderItem.setOrderId(rs.getInt("order_id"));
				orderItem.setOrderItemId(rs.getInt("order_item_id"));
				orderItem.setPicturePath(rs.getString("picture_path"));
				orderItem.setPrice(rs.getDouble("price"));
				orderItem.setTitle(rs.getString("title"));
				orderItemList.add(orderItem);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
		return orderItemList;
	}
}
